package com.itheima.health.config;


import org.quartz.spi.TriggerFiredBundle;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.config.AutowireCapableBeanFactory;
import org.springframework.scheduling.quartz.AdaptableJobFactory;
import org.springframework.stereotype.Component;

@Component("myAdaptableJobFactoty")
public class MyAdaptableJobFactoty extends AdaptableJobFactory {

    @Autowired
    AutowireCapableBeanFactory autowireCapableBeanFactory;

    /*
     * 该方法需要将实例化的任务对象手动的添加到springIOC容器并完成对象注入
     * */
    @Override
    protected Object createJobInstance(TriggerFiredBundle bundle) throws Exception {
        Object obj = super.createJobInstance(bundle);
        this.autowireCapableBeanFactory.autowireBean(obj);
        return obj;
    }

}
